import { Server } from 'socket.io'
import { createServer } from 'http'
const t = process.env.NODE_ENV === 'development' ? 3000 : 0
export default class Serve {
    io: Server;
    port: number | undefined;
    constructor(p: number | string) {
        const httpServer = createServer();
        this.io = new Server(httpServer, {
            cors: {
                origin: [`http://localhost:${p}`, 'file://*'],
                methods: ["GET", "POST"]
            }
        });
        httpServer.listen(t);
        const address = httpServer.address()
        if (typeof address === 'object' && address) {
            this.port = address.port
        }
    }
}